-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Improved cache handling #10
Conversation
- Adds option `cacheDir` - Choose the directory to use for caching - Adds option `clearCache` - Clears the cache before processing - Cache dir by default is under the package's `node_modules` folder - Relative `cacheDir` path will be relative to Vite's `<root>` dir - Absolute `cacheDir` path will be just that
08ab50b
to
282eed4
Compare
…-modules Feat: better cache handling without external modules
* Adds logging stats for files taken from cache (will be marked blue) * Adds cache key identifier (based on the used options) to distinguish caches. * Adds support for partial caches. Only missing and changed files will process. * Some cache logic adjustments * Some code refactoring/cleanup * Updated type definitions * Updated docs
Log preview when using cachePerformanceLogs from All blue marked items are taken from the cache. Evidently there's a huge time benefit using the cache. Re-process errored files and re-evaluate skipped variantsAlso note that errored/skipped files will re-process. Files that were skipped because of size are not. They are taken from the cache and re-evaluated for inclusion. If they are still larger, they will be removed from the output dir but kept in the cache (marked dimmed blue; see Partial processingWhen some of the output files are missing from the cache or have changed (for whatever reason), the cache feature can now handle partial processing for those variants alone. In this example I manually removed two files from the cache: |
* Removed duplicate `readFile` * More efficient checking, restoring and updating
LGTM 👍🏻 I've tested it in multiple production projects and it works great! |
The cache key option is really nice so I can force a full optimisation when I change some compression settings. |
Awesome! Yeah, it is somewhat impossible to serialize/stringify the Side note: some options (like Side note 2: the cache entries are in a file named with the cache key, while all the actual files are just in one folder. As long as their contents stays the same between configs, they can still be re-used I think. If this turns out to have buggy behavior, we can revert to putting all cache entries and files in a subfolder with the key name. |
I will merge this with the main branch into version 1.1.4 Feel free to submit issues if you encounter them or PRs if you have improvements! When I have more time I will make tests for the new feature to make sure all use cases are covered. |
clearCache
- Clears the cache before processingcacheDir
- Choose the directory to use for cachingcacheDir
by default is under the package's root folder innode_modules/.cache/vite-plugin-imagemin/<packageName>
cacheDir
path will be relative to Vite's<root>
dircacheDir
path will be just thatTODO